namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;

    public class PaintLineHorizontal : PaintLineBase
    {
        public PaintLineHorizontal()
        {
            base.LineType = PaintLineType.Horizontal;
            base.PlName_zh = "水平线";
        }

        public override void BeginMove()
        {
            if (base.PointList.Count != 0)
            {
                Point crossHairPoint = base.CgInstance.GetCrossHairPoint();
                base.BeginMovePoint = crossHairPoint;
                base.MoveType = 0;
                base.CgInstance.Cursor = Cursors.Hand;
                base.BeginMoveValue.Clear();
                base.BeginMoveValue.Add(base.PointList[0]);
            }
        }

        public override void Draw(Graphics g, List<PaintLineBase.PointValue> pList, Color curColor)
        {
            if (pList.Count != 0)
            {
                ChartDiv div = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                PaintLineBase.PointValue value2 = pList[0];
                float num = (base.CgInstance.GetY(base.OwnedPanelID, value2.Value, null) - div.Rect.Y) - div.TitleHeight;
                Brush brush = new SolidBrush(curColor);
                Pen pen = new Pen(brush) {
                    Width = (float) base.LineWidth
                };
                if (base.LineStyle != null)
                {
                    pen.DashPattern = base.LineStyle;
                }
                g.DrawLine(pen, 0f, num, base.CgInstance.GetWorkSpaceX(), num);
                pen.Dispose();
                brush.Dispose();
            }
        }

        public override bool Init(Point mp)
        {
            if (base.CgInstance.DataSource.Rows.Count > 0)
            {
                ChartDiv local1 = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                base.PointList.Clear();
                double valueByPoint = base.CgInstance.GetValueByPoint(mp);
                base.PointList.Add(new PaintLineBase.PointValue(0, "", valueByPoint));
                return true;
            }
            return false;
        }

        public override bool JudgeSelect()
        {
            if (base.PointList.Count == 0)
            {
                return false;
            }
            Point crossHairPoint = base.CgInstance.GetCrossHairPoint();
            PaintLineBase.PointValue value2 = base.PointList[0];
            float num = base.CgInstance.GetY(base.OwnedPanelID, value2.Value, null);
            return ((crossHairPoint.Y >= (num - (base.LineWidth * 2.5f))) && (crossHairPoint.Y <= (num + (base.LineWidth * 2.5f))));
        }

        public override double[] LineParam()
        {
            return null;
        }

        public override void Move()
        {
            if (base.PointList.Count != 0)
            {
                Point crossHairPoint = base.CgInstance.GetCrossHairPoint();
                ChartDiv div = base.CgInstance.DicChartDiv[base.OwnedPanelID];
                if ((crossHairPoint.Y >= (div.Rect.Y + div.TitleHeight)) && (crossHairPoint.Y <= (div.Rect.Bottom - div.CalenderScale.Height)))
                {
                    base.PointList[0] = new PaintLineBase.PointValue(0, "", base.CgInstance.GetMouseOverValue());
                }
            }
        }
    }
}

